package com.example.demoexample.view.recycleview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.demoexample.R;

import java.util.ArrayList;
import java.util.List;

public class RecycleActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private List<RecycleData> list;
    private List<RecycleData> list2;
    private List<RecycleData> list3;
    private Button btnAdd;
    private OneAdapter oneAdapter;
    private Button btnLinus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle);

        recyclerView = findViewById(R.id.recycleView);
        btnAdd = findViewById(R.id.btn_add);
        btnLinus = findViewById(R.id.btn_linus);

        list = new ArrayList<>();
        list2 = new ArrayList<>();
        list3 = new ArrayList<>();
        initData();

        oneAdapter = new OneAdapter(list);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(oneAdapter);

        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                oneAdapter.setData(list2);
            }
        });

        btnLinus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                oneAdapter.setData(list3);
            }
        });

    }

    private void initData(){

        for (int i=0;i<10;i++){
            RecycleData recycleData = new RecycleData();
            recycleData.title = "打地鼠";
            recycleData.name = "吃饭";
            recycleData.Money = "没钱";
            list.add(recycleData);
            list3.add(recycleData);
        }

        for (int i=0;i<5;i++){
            RecycleData recycleData2 = new RecycleData();
            recycleData2.title = "睡觉";
            recycleData2.name = "起床";
            recycleData2.Money = "等待";
            list2.add(recycleData2);

        }

    }

}
